<%@ page contentType="text/html; charset=utf-8" %>

<%@ include file="/WEB-INF/jsp/includeTop.jsp" %>

<script type="text/javascript" src="<c:url value='/plan/plan.js' />"></script>
<script type="text/javascript" src="<c:url value='/js/new_planjob.js' />"></script>

<table width="100%" border="0" cellpadding="0" cellspacing="5">
  <tr>
    <td valign="top">
      <table class="dbborder" width="100%" border="0" cellpadding="0" cellspacing="0">
        <tr>
          <td valign="bottom" class="blueTableBg">&nbsp;我的计划任务&nbsp;-&nbsp;编辑工作计划</td>
        </tr>
        <tr>
          <td>
            <table width="100%" border="0" cellpadding="0" cellspacing="5">
              <tr>
                <td>
                  <table width="100%" border="0" cellpadding="0" cellspacing="0">
                    <tr>
                      <td class="dashTopLeft"><img src="<c:url value='/images/spacer.gif' />" width="7" height="7"></td>
                      <td class="dashTop" width=100%><img src="<c:url value='/images/spacer.gif' />" width="7" height="7"></td>
                      <td class="dashTopRight"><img src="<c:url value='/images/spacer.gif' />" width="7" height="7"></td>
                    </tr>
                    <tr>
                      <td class="dashLeft"><img src="<c:url value='/images/spacer.gif' />" width="7" height="7"></td>
                      <td align="center">
                      <form id="planForm" method="post">
                        <table width="100%" border="0" cellpadding="0" cellspacing="3">
                          
                          <tr>
                            <td width="114" height="20" class="globalText">计划名称</td>
                            <td height="20" class="globalText">
                            	<input type="text" id="planName" class="txtbox required" size="20"  value="${plan.name}"/>
                            </td>
                          </tr>
                          <tr>
                            <td width="114" height="20" class="globalText">计划日期</td>
                            <td height="20" class="globalText">
                            	<input onclick="WdatePicker({minDate:'${nowDate}',dateFmt:'yyyy-MM-dd'});" type="text" id="planDate" class="txtbox required" size="20"  value="${plan.planDate}"/>
                            </td>
                          </tr>
                          <tr>
                            <td width="114" height="20" class="globalText">项目及任务信息</td>
                            <td height="20" class="globalText">
                            	<input type="button" class=" btnStyle" value="+添加项目" onclick="javascript:addProject()" />
                            </td>
                          </tr>
                          <tr>
                            <td colspan="2">
                            	<table id="mainTable" width="100%" border="0" cellpadding="0" cellspacing="3">
                            	</table>
                            </td>
                          </tr>
                          <tr>
                            <td>&nbsp;</td>
                            <td>&nbsp;</td>
                          </tr>
                          <tr>
                            <td align="center" colspan="2">
                              <table border="0" cellpadding="0" cellspacing="2">
                                <tr>
                                  <td><input type="button" class="btnStyle" value="  保存  " onclick="javascript:submitCreatePlan();"></td>
                                  <td>
                                  	<input onclick="javascript:window.history.back();" type="button" class="btnStyle" value=" 返回  ">
                                  </td>
                                </tr>
                              </table>
                            </td>
                          </tr>
                        </table>
                         </form>
                      </td>
                      <td class="dashRight"><img src="<c:url value='/images/spacer.gif' />" width="7" height="7"></td>
                    </tr>
                    <tr>
                      <td class="dashBottomLeft"><img src="<c:url value='/images/spacer.gif' />" width="7" height="7"></td>
                      <td class="dashBottom" width=100%><img src="<c:url value='/images/spacer.gif' />" width="7" height="7"></td>
                      <td class="dashBottomRight"><img src="<c:url value='/images/spacer.gif' />" width="7" height="7"></td>
                    </tr>
                  </table>
                </td>
              </tr>
            </table>
          </td>
        </tr>
      </table>
    </td>
  </tr>
</table>

<input type="hidden" value="${plan.id}" id="planId" />
<input type="hidden" value="${plan.version}" id="planVersion" />
<input type="hidden" value="${user.employee.empId}" id="empId" />
<input type="hidden" value="${plan.userLoginName}" id="userLoginName" />
<input type="hidden" value="${searchType}" id="searchType" />
<input type="hidden" value="${plan.type}" id="planType" />
<input type="hidden" value="${plan.assignedBy}" id="assignedBy" />


<div style="display:none;">
		<table>
								  <tr id="projectTr">
		                          	<td colspan="2">
		                          		<table class="dbborder" width="100%" border="0" cellpadding="0" cellspacing="1">
								         <tr class="rowHead">
								           <td colspan="5" width="50%" height="20" nowrap align="center" class="globalTextBold">
								           		项目
								           		<input projectIndex="" readonly="readonly" class="dynamic required" id="project_name_" type="text" onclick="javascript:chooseProject(this.getAttribute('projectIndex'));" />
								           		<input projectIndex="" projectId="" class="dynamic btnStyle" type="button" value="选择项目" onclick="javascript:chooseProject(this.getAttribute('projectIndex'));" />
								           </td>
								           <td colspan="5" width="40%" height="20" nowrap align="center" class="globalTextBold">
								           </td>
								           <td colspan="1" width="10%" height="20" nowrap align="center" class="globalTextBold">
								           		<input projectIndex="" class="dynamic btnStyle"  value="+添加任务" type="button" onclick="addTask(this.getAttribute('projectIndex'))" />
								           </td>
								         </tr>
								         <tbody id="task_list_">
								         	
								         </tbody>
								       </table>
		                          	</td>
		                          </tr>
		                          
		                          <tr id="spacingTr">
		                          	<td colspan="2">
		                          		&nbsp;
		                          	</td>
		                          </tr>


									<tr class="dynamic_task" id="taskTr" class="rowEven">
							         	<td class="taskNum dynamic globalText" taskIndex="" projectIndex="" height="20">
										</td>
							         	<td height="20" class="globalText">
							         		<input id="task_name_"  style="width: 115px;" jobId="" type="text" taskIndex="" projectIndex="" class="dynamic required" onclick="chooseTask(this.getAttribute('taskIndex'),this.getAttribute('projectIndex'));"/>
										</td>
<!-- 							         	<td height="20" class="globalText"> -->
<!-- 							         		<input taskIndex="" class="dynamic btnStyle" value="选择" type="button" onclick="chooseTask(this.getAttribute('taskIndex'));" /> -->
<!-- 							         	</td> -->
							         	<td height="20" class="globalText">
							         		终端
							         	</td>
							         	<td height="20" class="globalText">
							         		<input id="terminal_info_" style="width: 145px;" channelCode="" channelAddress="" projectIndex="" type="text" taskIndex="" class="dynamic required" onclick="chooseChannel(this.getAttribute('taskIndex'),this.getAttribute('projectIndex'));"/>
							         		<a class="dynamic" taskIndex="" id="memoTip_" href="javascript:;"><font style="color: red;">备忘</font></a>
							         	</td>
<!-- 							         	<td height="20" class="globalText"> -->
<!-- 							         		<input taskIndex="" projectIndex="" class="dynamic btnStyle" value="选择" type="button" onclick="chooseChannel(this.getAttribute('taskIndex'),this.getAttribute('projectIndex'));" /> -->
<!-- 							         	</td> -->
							         	<td height="20" class="globalText">
							         		开始时间
							         	</td>
							         	<td height="20" class="globalText">
							         		<input class="required" id="startTime"  style="width: 65px;" type="text" />
							         	</td>
							         	<td height="20" class="globalText">
							         		截止时间
							         	</td>
							         	<td height="20" class="globalText">
							         		<input class="required" id="endTime" style="width: 65px;" type="text" />
							         	</td>
							         	<td height="20" class="globalText">
							         		<input projectIndex="" class="dynamic btnStyle" taskIndex="" onclick="javascript:delTask(this)"  type="button" class="" value="删  除" onclick="javascript:doSubmit()">
							         	</td>
							         </tr>
							         
	</table>
</div>




<script>
	$().ready(function() {
		var validate=$("#planForm").validate({
			showErrors: customShowErrors,
			onfocusout:false,
			onkeyup:false,
			onclick:false
		});
	});
	
	var planJobs=new Array();
	var projectCodes=new Array();
	
	<c:forEach var="planProject" items="${plan.planProjects}" varStatus="status">
		<c:forEach var="planJob" items="${planProject.planJobs}" varStatus="status">
			planJobs.push({
				jobId:"${planJob.job.id}",
				name:"${planJob.job.name}",
			    storeCode:"${planJob.storeCode}",
			    storeAddress:"${planJob.storeAddress}",
				storeName:"${planJob.storeName}",
				projectName:"${planProject.projectName}",
				projectCode:"${planProject.projectCode}",
				projectId:"${planProject.projectId}",
				startTime:"${planJob.startTime}",
				endTime:'${planJob.endTime}',
				status:'${planProject.plan.status}'
			});
			
			var tempTag=true;
			for(var i=0;i<projectCodes.length;i++){
				if(projectCodes[i]=="${planProject.projectCode}"){
					tempTag=false;
				}
			}
			if(tempTag){
				projectCodes.push("${planProject.projectCode}");
			}
		</c:forEach>
	</c:forEach>
	
	for(var j=0;j<projectCodes.length;j++){
		var projectCode=projectCodes[j];
		var projectTr=addProject();

		var pis=$(projectTr).find("[projectIndex]");
		var index=$(pis[0]).attr("projectIndex");
		
		var temp=0;
		for(var i=0;i<planJobs.length;i++){
			var planJob=planJobs[i];
			if(planJob.projectCode!=projectCode){
				continue;
			}
			if(temp==0){
				$("#project_name_"+(projectIndex-1)).val(planJob.projectName);
				$("#project_name_"+(projectIndex-1)).attr("projectcode",planJob.projectId);
				$("#project_name_"+(projectIndex-1)).attr("projectid",planJob.projectCode);
			}
			var taskTr=addTask(index);
			
			$(taskTr).find("[id^='task_name_']").attr("jobid",planJob.jobId);
			$(taskTr).find("[id^='task_name_']").val(planJob.name);
			
			$(taskTr).find("[id^='terminal_info_']").attr("channeladdress",planJob.storeAddress);
			$(taskTr).find("[id^='terminal_info_']").attr("channelcode",planJob.storeCode);
			$(taskTr).find("[id^='terminal_info_']").val(planJob.storeName);
			
			$(taskTr).find("[id^='memoTip_']").bind("click",function(){
				openMemoTip(planJob.storeCode,this);
			});
			
			$(taskTr).find("[id^='startTime_']").val(planJob.startTime);
			$(taskTr).find("[id^='endTime_']").val(planJob.endTime);
			
			temp++;
		}
	}
	
</script>


